In [1]:
#Set up the notebook to work with the V-REP simulator
%run 'Set-up.ipynb'
%run 'Loading scenes.ipynb'
In [4]:
#Load the Pioneer models
%run 'vrep_models/PioneerP3DX.ipynb'
In [7]:
%vrep_robot_methods PioneerP3DXL
In [3]:
%%vrepsim '../scenes/LineFollowerPioneer.ttt' PioneerP3DXL
# black color : 43
# white-gray color : -53
import time
while True:
lclr = robot.color_left()
rclr = robot.color_right()
if lclr > 10:
robot.rotate_left(0.3)
if rclr > 10:
robot.rotate_right(0.3)
if lclr < -20 and rclr < -20:
robot.move_forward(1.5)
time.sleep(0.001)
In [64]:
import time
def line_follow(pioneer):
lclr = pioneer.color_left()
rclr = pioneer.color_right()
if lclr > 10:
pioneer.rotate_left(0.3)
if rclr > 10:
pioneer.rotate_right(0.3)
if lclr < -20 and rclr < -20:
pioneer.move_forward(1.5)
time.sleep(0.001)
In [65]:
sensorText1.description = 'Left light'
sensorText2.description = 'Max left light'
display(sensorText1,sensorText2)
In [7]:
%%vrepsim '../scenes/LineFollowerPioneer.ttt' PioneerP3DXL
maxval=robot.color_left()
while True:
line_follow(robot)
sensorText1.value =str(robot.color_left())
maxval = robot.color_left() if robot.color_left() > maxval else maxval
sensorText2.value=str(maxval)
In [57]:
%matplotlib inline
import pandas as pd
df=pd.DataFrame(columns=['Time','Left sensor'])
#If we want to set df directly within the evaluated code in the vrepsim block
#we need to specify it in that block using: global df
#However, objects are mutable in that scope, so pass the dataframe that way
data={'df':df}
In [58]:
%%vrepsim '../scenes/LineFollowerPioneer.ttt' PioneerP3DXL
maxval=robot.color_left()
start_time = time.time()
while True:
line_follow(robot)
sensorText1.value =str(robot.color_left())
maxval = robot.color_left() if robot.color_left() > maxval else maxval
sensorText2.value=str(maxval)
elapsed_time = time.time() - start_time
data['df']=pd.concat([data['df'],pd.DataFrame([{'Time':elapsed_time,
'Left sensor':robot.color_left()}])])
In [59]:
data['df'].plot(x='Time',y='Left sensor');
In [ ]: